import Vue from 'vue'
import VueRouter from 'vue-router'
import DashView from '../views/DashView.vue'
import HomeView from '../views/HomeView.vue'

// 所有的其他三方模块必须通过 Vue.use 注册
Vue.use(VueRouter)

// 路由配置
// const routes = [
//   {
//     path: '/', // 访问路径
//     name: 'home', // 路由名字
//     component: HomeView // 当前路径要渲染的组件
//   },
//   {
//     path: '/about/:user', // :user 表示未知，即任意字符串，我们可以匹配 /about/foo，也可以匹配 /about/bar
//     name: 'about',
//     // route level code-splitting
//     // this generates a separate chunk (about.[hash].js) for this route
//     // which is lazy-loaded when the route is visited.
//     component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
//   },
//   {
//     path: '/login',
//     name: 'Login',
//     component: () => import('../views/LoginView.vue')
//   }
// ]

// 嵌套路由
const routes = [
  {
    path: '/',
    name: 'dash',
    component: DashView,
    children: [ // 设置子路由
      {
        path: '', // 默认子路由
        name: 'home',
        component: HomeView,
      },
      {
        path: 'about/:user', // 子路由不能以 / 开头
        name: 'about',
        component: () => import('../views/AboutView.vue')
      },
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/LoginView.vue')
  }
]

// 实例化路由
const router = new VueRouter({
  mode: 'history',
  routes
})

export default router
